<?php
// Setup globals
// @todo: Get these out of template
global $wp_query;
// Setup image width and height variables
// @todo: Investigate if these are still needed here
$image_width = get_option('single_view_image_width');
$image_height = get_option('single_view_image_height');
?>
<section class="content" style="margin-top: -110px;">
    <div class="container-2">
        <div style="clear:both; display:block; height:40px"></div>
        <?php while (wpsc_have_products()) : wpsc_the_product(); ?>
            <div class="zoom-section">    	  
                <div class="zoom-small-image">
                    <?php if (wpsc_the_product_thumbnail()) : ?>
                        <a href='<?php $a = wpsc_the_product_image();
                echo $a[0]; ?>'title="<?php echo wpsc_the_product_title(); ?>" class='cloud-zoom' id="zoom1" rel="position:'inside',showTitle:false,adjustX:-4,adjustY:-4">
                            <img alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo $a[0]; ?>" style="width: 300px;height: 300px;"/>
                        </a>
                    <?php else: ?>
    <?php endif; ?>
                </div>
                <div class="zoom-desc">
                    <p>
                        <?php $list_product = get_List_Product_Image(wpsc_the_product_id()); ?>
                        <?php if (is_array($list_product)) { ?>
        <?php foreach ($list_product as $list) { ?>
                                <a href='<?php echo $list->guid; ?>' class='cloud-zoom-gallery' title='Red' rel="useZoom: 'zoom1', smallImage: '<?php echo $list->guid; ?>' ">
                                    <img  class="zoom-tiny-image" src="<?php echo $list->guid; ?>" alt = "Thumbnail 1"/>
                                </a>
                                <?php
                            }
                        }
                        ?>
                    </p>
                </div>
            </div><!--zoom-section end-->
            <div class="prod-detail" style="margin-right: -70px;">
                <h3><a class="wpsc_product_title"><?php the_title(); ?></a></h3>
                <span class="price"><small><?php echo substr(wpsc_product_normal_price(), 0, -7); ?> VND</small>
    <?php echo substr(wpsc_the_product_price(), 0, -7); ?>VND
                </span>
                <!--<form action="#">
                    Choose you sizes :&nbsp;
                    <select>
                        <option>Large</option>
                        <option>Medium</option>
                        <option>Small</option>
                        <option>X-Large</option>
                        <option>X-Small</option>
                    </select>
                    &nbsp;&nbsp;
                    Quantity:&nbsp;
                    <input value="1" type="text">                             
                </form>-->
            <!--<a href="JavaScript:void(0);" onclick="return click_addtocart(<?php echo wpsc_the_product_id(); ?>);">Add to Cart</a>-->
                <form class="product_form"   enctype="multipart/form-data" action="<?php echo get_page_link(31); ?>" 
                      method="post" name="product_<?php echo wpsc_the_product_id(); ?>" 
                      id="product_<?php echo wpsc_the_product_id(); ?>" >
                    <input type="hidden" name="page_id" value="31"/>
                    <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
                    <input  type="submit"  value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button a" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
                </form>
                <span class="cart-button">
                    <a href="JavaScript:void(0);" onclick="return click_addtocart(<?php echo wpsc_the_product_id(); ?>);">Mua Hàng</a>
                </span>
                <form onsubmit="submitform(this);
                                return false;" action="<?php echo esc_url(wpsc_this_page_url()); ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_extra_<?php echo wpsc_the_product_id(); ?>">
                    <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="prodid"/>
                    <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="item"/>
                </form>
                <div id="tab" style="margin-right: 45px;">
                    <ul class="nav">
                        <li class="nav-one"><a href="#details">Chi Tiết</a></li>
                        <li class="nav-two"><a href="#specs"  class="current">Thông Số</a></li>
                        <li class="nav-four last"><a href="#tags">Hướng Dẫn Thanh Toán</a></li>
                    </ul>
                    <div class="list-wrap">
                        <ul id="details" class="hide">
                            <li><span>Tên Sản Phẩm:</span><?php the_title(); ?></li>
                            <li><span>Trạng Thái:</span> In Stock</li>
                            <li><span>Giá:</span> <?php echo substr(wpsc_the_product_price(), 0, -5); ?></li>
                        </ul>
                        <div id="specs">
    <?php the_content(); ?>
                        </div>
                        <ul id="tags" class="hide">
                            <!--<li><a href="#">Office Products</a></li>
                            <li><a href="#">Paper</a></li>
                            <li><a href="#">Breakroom</a></li>
                            <li><a href="#">Furniture</a></li>
                            <li><a href="#">Ink & Toner</a></li>
                            <li><a href="#">Cleaning</a></li>-->
                        </ul>
                    </div>
                </div>
            </div><!--prodetail-->
            <?php
        // end product
        endwhile;
        ?>
        <div class="relatedprod">
            <h4>Sản Phẩm Cùng Loại</h4>
            <?php
            //lấy sản phẩm liên quan
            $id_product_current = wpsc_the_product_id();
            $catarogy_current_id_array = $wpdb->get_row("SELECT slug FROM wp_terms,wp_term_relationships WHERE term_id=term_taxonomy_id AND object_id=" . $id_product_current);
            $myposts = my_product_with_categoty($id_product_current, $catarogy_current_id_array);
            foreach ($myposts as $post) : setup_postdata($post);
                if (wpsc_the_product_id() == $id_product_current)
                    continue;
                ?>
                <div class="entry">
                    <div class="da-thumbs">
                        <div class="div-related">
                            <?php if (wpsc_show_thumbnails()) : ?>
                                <?php if (wpsc_the_product_thumbnail()) : ?>
                                    <img id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>">
                                <?php else: ?>
                                    <img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php esc_attr_e('No Image', 'wpsc'); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />
                                <?php endif; ?>
                                <?php
                                if (gold_cart_display_gallery()) :
                                    echo gold_shpcrt_display_gallery(wpsc_the_product_id(), true);
                                endif;
                                ?>
    <?php endif; ?>
                            <article class="da-animate da-slideFromRight" style="display: block;">
                                <p> <a href="<?php echo $post->guid; ?>" class="link tip" title="Xem chi tiết"></a>&nbsp;
                                    <a href="JavaScript:void(0);" onclick="return click_addtocart(<?php echo wpsc_the_product_id(); ?>);" 
                                       class="cart tip" title="Mua Hàng"></a>&nbsp;&nbsp;
                                </p>
                            </article>
                            <form class="product_form"   enctype="multipart/form-data" action="<?php echo get_page_link(31); ?>" 
                                  method="post" name="product_<?php echo wpsc_the_product_id(); ?>" 
                                  id="product_<?php echo wpsc_the_product_id(); ?>" >
                                <input type="hidden" name="page_id" value="31"/>
                                <input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
                                <input  type="submit"  value="<?php _e('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button a" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
                            </form>
                        </div>
                    </div>
                    <h3>
                        <a href="<?php echo $post->guid; ?>">
    <?php echo wpsc_the_product_title(); ?>
                        </a>
                    </h3>
                    <span><small><?php
                            $price_o = wpsc_product_normal_price();
                            echo substr($price_o, 0, -5);
                            ?></small>
                        Còn 
    <?php echo substr(wpsc_the_product_price(), 0, -5); ?>
                    </span> 
                </div>      
                <?php
                //the end lấy sản phẩm 
            endforeach;
            ?>
        </div>
    </div><!--end:container-2-->
</section>
<?php
function py_slice($input, $slice) {
    $arg = explode(':', $slice);
    $start = intval($arg[0]);
    if ($start < 0) {
        $start += strlen($input);
    }
    if (count($arg) === 1) {
        return substr($input, $start, 1);
    }
    if (trim($arg[1]) === '') {
        return substr($input, $start);
    }
    $end = intval($arg[1]);
    if ($end < 0) {
        $end += strlen($input);
    }
    return substr($input, $start, $end - $start);
}
?>